﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using matrixdotnet.CommonDAL;
using matrixdotnet.Common;
using matrixdotnet.CommonDALImp;

namespace Cinema.DAL
{
    public interface IFilmDataEntityFactory : IDataEntityFactoryL<FilmUniqueKey, IFilm, IFilmDataEntity, FilmLazyEntity>
    {
        IFilm Create(string name,
            string description,
            string director,
            string imagePath,
            PositiveValue<short> duration,
            DateTime? discontinueDate);
    }

    public class FilmDataEntityFactory :
        DataEntityFactoryL<FilmUniqueKey, IFilm, IFilmDataEntity, FilmLazyEntity>,
        IFilmDataEntityFactory
    {
        protected internal FilmDataMapper DataMapper { get; set; }

        public FilmDataEntityFactory(UnitOfWork uow)
            : base(uow)
        {
        }

        public IFilm Create(string name,
            string description,
            string director,
            string imagePath,
            PositiveValue<short> duration,
            DateTime? discontinueDate)
        {
            return new Film(
                name, description, director, imagePath, duration, discontinueDate);
        }

        protected override IFilmDataEntity CreateEntity(long identity, IFilm businessEntity, long version)
        {
            return new FilmDataEntity(identity, businessEntity, version);
        }

        protected override IFilmDataEntity CreateEntity(IFilm businessEntity)
        {
            return new FilmDataEntity(businessEntity);
        }

        protected override FilmLazyEntity CreateEntity(long identity)
        {
            return new FilmLazyEntity(identity, DataMapper);
        }
    }
}
